Skip to content

Sarah S - Seattle#13

Open
sarahstandish wants to merge 1 commit intoAda-C16:masterfrom
sarahstandish:master
Open

Sarah S - Seattle#13
sarahstandish wants to merge 1 commit intoAda-C16:masterfrom
sarahstandish:master

Conversation

@sarahstandish
Copy link
Copy Markdown

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The only requirement about a node vis a vis its children is that the node must be smaller (min heap) or larger (max heap)
Could you build a heap with linked nodes? Yes, though you might need a different method to find the parent/child nodes.
Why is adding a node to a heap an O(log n) operation? Bc we need to heap down.
Were the heap_up & heap_down methods useful? Why? Yes. The only way to resort nodes.

Copy link
Copy Markdown

@kyra-patton kyra-patton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨💫 Nice work! I left some comments on time and space complexity. Let me know what questions you have.

🟢

Comment thread heaps/heap_sort.py


def heap_sort(list):
def heap_sort(l):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread heaps/min_heap.py
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(log n) where n is the length of self.store (??)
Space Complexity: O(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Nice job on the time complexity, however space complexity would also be O(log n) because of the recursive call stack created by heap_up

Comment thread heaps/min_heap.py
else:
return

def remove(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Time and space complexity?

Comment thread heaps/min_heap.py
@@ -44,31 +120,13 @@ def __str__(self):

def empty(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread heaps/min_heap.py

This could be **very** helpful for the add method.
Time complexity: O(log n) where n is the length of self.store (??)
Space complexity: O(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ However because of heap_up's recursive call, space complexity is O(log n).

Comment thread heaps/min_heap.py

return removed.value

def heap_down(self, index):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants